<template>
  <div id="c_top_menu">
    <div class="drag"></div>
    <div class="main">
      <div class="topMenu">
        <div class="logo">
          <img src="@/assets/icon.png" alt="" />
          <p>{{ title }}</p>
        </div>
        <ul class="menu">
          <li
            class="miniSize boticon bot-config"
            :class="configEnter && 'miniEnter'"
            title="配置"
            @mousedown="configEnter = true"
            @mouseup="configEnter = false"
            @click="config"
          ></li>
          <li
            class="miniSize boticon bot-minisize"
            :class="miniEnter && 'miniEnter'"
            title="最小化"
            @mousedown="miniEnter = true"
            @mouseup="miniEnter = false"
            @click="miniSize"
          ></li>
          <li
            class="close boticon bot-close"
            :class="closeEnter && 'closeEnter'"
            title="关闭"
            @mousedown="closeEnter = true"
            @mouseup="closeEnter = false"
            @click="closeBro"
          ></li>
        </ul>
      </div>
    </div>
  </div>
</template>

<script>
import { mapGetters } from "vuex";
export default {
  name: "c_top_menu",
  data() {
    return {
      // 顶部菜单的按下状态
      configEnter: false,
      miniEnter: false,
      closeEnter: false,
      configAnimate: false,
      title: document.title,
    };
  },
  computed: {
    ...mapGetters(["configShow"]),
  },
  methods: {
    // 最小化
    miniSize() {
      this.miniEnter = false;
      this.$et.ipcRenderer.send("win.min");
    },
    // 关闭
    closeBro() {
      this.$store.dispatch("Set_Show", false);
      setTimeout(() => {
        this.closeEnter = false;
        this.$et.ipcRenderer.send("win.close");
      }, 300);
    },
    // 配置
    config() {
      // 等待动画结束后才允许点击
      if (!this.configAnimate) {
        this.configAnimate = true;
        this.$store.dispatch("Set_ConfigShow", !this.configShow);
        setTimeout(() => {
          this.configAnimate = false;
        }, 1000);
      }
    },
  },
};
</script>

<style lang="scss" scoped>
#c_top_menu {
  position: relative;
  height: 40px;
  .drag {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 40px;
    z-index: 10;
    background: rgba($color: #fff, $alpha: 0.6);
    -webkit-app-region: drag;
  }
  .main {
    position: relative;
    z-index: 10;
    background: rgba($color: #fff, $alpha: 0.6);
    .topMenu {
      display: flex;
      align-items: center;
      justify-content: center;
      padding-left: 10px;
      .logo {
        display: flex;
        align-items: center;
        height: 40px;
        img {
          width: 20px;
          margin-right: 10px;
        }
        p {
          font-size: 14px;
          font-weight: bold;
        }
      }
      .menu {
        display: flex;
        align-items: center;
        position: absolute;
        right: 0;
        li {
          width: 40px;
          height: 40px;
          line-height: 40px;
          text-align: center;
          list-style: none;
          font-size: 18px;
          font-weight: bold;
          transition: 0.3s;
          -webkit-app-region: no-drag;
          &.miniSize:hover {
            background: rgba($color: #909399, $alpha: 0.3);
          }
          &.close:hover {
            background: rgba($color: #f56c6c, $alpha: 1);
            color: #fff;
          }
          &.close.closeEnter {
            background: rgba($color: #f56c6c, $alpha: 0.8);
          }
          &.miniSize.miniEnter {
            background: rgba($color: #909399, $alpha: 0.5);
          }
        }
      }
    }
  }
}
// 修改ElementUi的默认样式
:deep .el-empty__description p {
  font-size: 12px;
}
</style>